<template>
  <d2-container class="page">
    <div style="margin: 20px;"></div>
    <el-form ref="ruleForm" :rules="rules" label-width="80px" :model="formLabelAlign">
      <el-form-item prop="nickname" label="用户昵称">
        <el-input v-model="formLabelAlign.nickname"></el-input>
      </el-form-item>
      <el-form-item prop="loginId" label="登录名">
        <el-input v-model="formLabelAlign.loginId"></el-input>
      </el-form-item>
      <el-form-item prop="loginPwd" label="登录密码">
        <el-input v-model="formLabelAlign.loginPwd"></el-input>
      </el-form-item>
      <el-form-item>
        <el-button @click="handleUpdateInfo('ruleForm')" type="primary">添加</el-button>
      </el-form-item>
    </el-form>
  </d2-container>
</template>

<script>
import api from "@/api";

export default {
  data() {
    return {
      rules: {
        loginId: [
          { required: true, message: '请输入用户名', trigger: 'blur' },
        ],
        loginPwd: [
          { required: true, message: '请输入用户密码', trigger: 'change' }
        ],
        nickname: [
          { required: true, message: '请输入用户昵称', trigger: 'change' }
        ],
      },
      formLabelAlign: {
        nickname: '',
        loginId: '',
        loginPwd: ""
      }
    };
  },
  methods: {
    async handleUpdateInfo(formName) {

      this.$refs[formName].validate(async (valid) => {
        if (valid) {
          console.log(this.formLabelAlign)
          await api.SYS_ADD_ADMIN(this.formLabelAlign)
          this.$message.success("新增成功")
        } else {
          console.log('error submit!!');
          return false;
        }
      });

    }
  }
}
</script>

<style lang="scss" scoped>

</style>
